package com.qboot.core.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger 配置
 *
 * @author Tellsea
 * @date 2022/11/25
 */
@Configuration
@EnableSwagger2
@EnableKnife4j
@Import(BeanValidatorPluginsConfiguration.class)
public class SwaggerConfig {

    @Bean("startDocket")
    public Docket startDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("启动模块：qboot-start")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.qboot.start.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean("generateDocket")
    public Docket generateDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("代码生成模块：qboot-tool-generate")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.qboot.generate.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean("systemDocket")
    public Docket systemDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("系统模块：qboot-system")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.qboot.system.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean("monitorDocket")
    public Docket monitorDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("监控模块：qboot-tool-monitor")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.qboot.monitor.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    @Bean("commonDocket")
    public Docket commonDocket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("常用模块：qboot-common")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.qboot.common.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("接口文档")
                .description("开发文档在线接口")
                .contact(new Contact("Tellsea", "https://gitee.com/tellsea/qboot", "3210054449@qq.com"))
                .version("1.0.0")
                .build();
    }
}
